package com.vm.runtimedata.obj;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class NewObjectTest {

    public static void main(String[] args) {
        Class clazz= null;
        try {
            clazz = Class.forName("com.vm.runtimedata.obj.C");
//            Method method=c.getMethod("show");
//        method.invoke(c.newInstance());  Java9之后显示已过时
            try {
                C c = (C) clazz.getDeclaredConstructor(String.class).newInstance("哈哈");
                c.print();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}


